// dosheader.cpp
// Written by, Sohail Qayum Malik[sqm@cyberian.pk]

/* For debuging purposes, should be gone when done */
#include <iostream>
/*  For debugging purposes ends here */

#include "dosheader.h"

int dosheader(char const*const*const argv, arg_history common_arg, arg_history dosheader_arg) throw(args_exception) {

   int ret = 0;
   arg_history dh_d;

   try {
   
      argument<arg_history>::pointer ptr = argument<arg_history>::NewE(dosheader_arg.get_argc(), argv + dosheader_arg.get_index() , COMMANDS);
      argument<arg_history>::iterator itB(ptr->begin());
	  
	  dh_d = itB[DOSHEADER_DUMP]; 
	  	  
	  for ( int i = 1; i < common_arg.get_argc(); i++ ) {
	  
	      parser( (argv + common_arg.get_index())[i], callback_dosheader, PARSER_DOS_HEADER );
		  
		  if ( /* dh_d == DOSHEADER_DUMP*/ dh_d(DOSHEADER_DUMP) ) {
		  
		     parser( (argv + common_arg.get_index())[i], callback_dosheader_dump, PARSER_DOS_HEADER_DUMP );
		  }		  
      }
	  
	  for ( int i = 1; i < itB[COMMON].get_argc(); i++) {
	  
	      parser( (argv + dosheader_arg.get_index() + itB[COMMON].get_index())[i], callback_dosheader, PARSER_DOS_HEADER);
		  
		  if ( /* dh_d == DOSHEADER_DUMP*/ dh_d(DOSHEADER_DUMP) ) {
		  
		     parser( (argv + dh_d.get_index() + itB[COMMON].get_index())[i], callback_dosheader_dump, PARSER_DOS_HEADER_DUMP ); 
		  }
	  }       	  	     
   }
   catch(args_exception &e) {
   
      throw(e);   
   }
    
   return ret;
}